<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php 
if(!$_POST)
{
	if($adc->getAdCats())
	{
		$forms = $fc->getForms();
		foreach($adc->getAdCats() as $item)
		{
			if((intval($_GET['typeId']) == 0) || (intval($_GET['typeId']) == $item->getTypeId()))
			{
			?>
			<tr class="items">
				<td class="first center"><?php echo $item->getId(); ?></td>
				<td>
					<input type="hidden" name="Id[]" value="<?php echo $item->getId(); ?>" />
					<div style="display:none;"><?php echo $item; ?></div>
					<input class="select_list" type="checkbox" name="selected[]" value="<?php echo $item->getId(); ?>" />
				</td>
				<td>
					<select class="small" name="TypeId[]" onchange="submit();">
						<?php 
						echo '<option value="0" '.$txt->getIsSelectedHTML($item->getTypeId(), 0) .'>'.ucfirst($txt->getWord('undefined')).'</option>';
						if($adc->getAdTypes())
						{
							foreach($adc->getAdTypes() as $type)
							{ echo '<option value="'.$type->getId().'" '.$txt->getIsSelectedHTML($item->getTypeId(), $type->getId()) .'>'.$type->getTitle().'</option>'; }
						}
						?>
					</select>
				</td>
				<td>
					<select class="small" name="ParentId[]" onchange="submit();">
						<?php 
						echo '<option value="0" '.$txt->getIsSelectedHTML($item->getParentId(), 0) .'>'.ucfirst($txt->getWord('none')).'</option>';
						if($adc->getAdCats())
						{
							foreach($adc->getAdCats() as $adcat)
							{ 
								if($adcat->getId() != $item->getId())
								{
									if($item->getTypeId() > 0)
									{
										if($item->getTypeId() == $adcat->getTypeId())
										{ echo '<option value="'.$adcat->getId().'" '.$txt->getIsSelectedHTML($item->getParentId(), $adcat->getId()) .'>'.$adcat->getTitle().'</option>'; }
									}
									else
									{ echo '<option value="'.$adcat->getId().'" '.$txt->getIsSelectedHTML($item->getParentId(), $adcat->getId()) .'>'.$adcat->getTitle().'</option>'; }
								}
							}
						}
						?>
					</select>
				</td>
				<td><input class="small-m" name="Title[]" type="text" value="<?php echo $item->getTitle() ?>" maxlength="80" /></td>
				<td><input class="small" name="TitleEn[]" type="text" value="<?php echo $item->getTitleEn() ?>" maxlength="100" /></td>
				<td>
					<select class="small" name="FormId[]" onchange="submit();">
						<?php 
						echo '<option value="0" '.$txt->getIsSelectedHTML($item->getLevel(), 0) .'>'.ucfirst($txt->getWord('ad_type').' '.$txt->getWord('defined')).'</option>';
						if($fc->getForms())
						{
							foreach($fc->getForms() as $form)
							{ echo '<option value="'.$form->getId().'" '.$txt->getIsSelectedHTML($item->getFormId(), $form->getId()) .'>'.$form->getTitle().'</option>'; }
						}
						?>
					</select>
				</td>
				<td>
					<select class="small" name="FormBuyId[]" onchange="submit();">
						<?php 
						echo '<option value="0" '.$txt->getIsSelectedHTML($item->getLevel(), 0) .'>'.ucfirst($txt->getWord('ad_type').' '.$txt->getWord('defined')).'</option>';
						if($fc->getForms())
						{
							foreach($fc->getForms() as $form)
							{ echo '<option value="'.$form->getId().'" '.$txt->getIsSelectedHTML($item->getFormBuyId(), $form->getId()) .'>'.$form->getTitle().'</option>'; }
						}
						?>
					</select>
				</td>
                <td class="center xsmall">
                    <?php echo $commander->getCommandButton('up', $item->getId()); ?>
                    <?php echo $commander->getCommandButton('down', $item->getId()); ?>
                </td>
				<td>
					<?php echo $commander->getActivationFieldsObjectAjax($item); ?>
					<input type="hidden" name="Active[]" value="<?php echo $item->getActive(); ?>" />
				</td>
				<td class="center">
					<a href="?con=<?php echo $_REQUEST['con']; ?>&amp;editor=cat&amp;cat=<?php echo $item->getId(); ?>"><img title="<?php echo ucfirst($txt->getWord('edit')); ?>" class="icon command" src="<?php echo SYSICONS_URL; ?>configure_16.gif" /></a>
				</td>
				<td class="last center">
				<img title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('ad_type')); ?>" class="icon command" src="<?php echo SYSICONS_URL; ?>delete_16.gif" onclick="deleteDialog(<?php echo $item->getId(); ?>);" />
				</td>
			</tr>
			<?php
			}
		}
	}
	else
	{
		?>
		<tr class="items">
			<td class="first center">0</td>
			<td class="center"><input class="select_list" type="checkbox" name="selected[]" value="0" /></td>
			<td><?php echo ucfirst($txt->getWord('no_items')); ?></td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
            <td>&nbsp;</td>
			<td>&nbsp;</td>
			<td class="last center">&nbsp;</td>
		</tr>
		<?php
	}
}
?>